GATE Exam  >  GATE Questions  >   Which of the following is correct output for... Start Learning for Free
Which of the following is correct output for the program code given below?
main( )
{
void pr( );
pr ( );
pr ( );
pr ( );
void pr ( )
{
static int i = 1;
printf (“%c”, (65+ i ++));
}
}
  • a)
    BCD
  • b)
    BBB
  • c)
    ABC
  • d)
    None of these
Correct answer is option 'A'. Can you explain this answer?
Verified Answer
Which of the following is correct output for the program code given b...
The correct output is “BCD” when the function pr ( ) is first called the value of i is initialized to 1.
After the pr ( ) completes its execution i = 2 is retained for it’s next call as “i” is a static variable.
∴ 65 + 1 = 66 = B
65 + 2 = 67 = C
65 + 3 = 68 = D
∴ BCD is the correct output.
View all questions of this test
Most Upvoted Answer
Which of the following is correct output for the program code given b...
Understanding the Program Structure
The program defines a function `pr()` that utilizes a static variable `i`. Static variables maintain their value between function calls.
Key Components of the Code
- Static Variable: `static int i = 1;` initializes `i` to 1 and retains its value across multiple calls to `pr()`.
- Function Calls: The function `pr()` is called three times.
Function Logic
- Each call to `pr()` increments `i` and prints the corresponding ASCII character:
- First Call:
- `i` is 1.
- Prints `65 + 1` → `66`, which corresponds to 'B'.
- Second Call:
- `i` is now 2.
- Prints `65 + 2` → `67`, which corresponds to 'C'.
- Third Call:
- `i` is now 3.
- Prints `65 + 3` → `68`, which corresponds to 'D'.
Output Sequence
- The output from the three calls will be 'B', 'C', and 'D' respectively.
Final Output
Putting it all together, the output of the program when `pr()` is called three times will be:
- Output: BCD
Therefore, the correct answer is option A.
Explore Courses for GATE exam
Which of the following is correct output for the program code given below?main( ){void pr( );pr ( );pr ( );pr ( );void pr ( ){static int i = 1;printf (“%c”, (65+ i ++));}}a)BCDb)BBBc)ABCd)None of theseCorrect answer is option 'A'. Can you explain this answer?
Question Description
Which of the following is correct output for the program code given below?main( ){void pr( );pr ( );pr ( );pr ( );void pr ( ){static int i = 1;printf (“%c”, (65+ i ++));}}a)BCDb)BBBc)ABCd)None of theseCorrect answer is option 'A'. Can you explain this answer? for GATE 2024 is part of GATE preparation. The Question and answers have been prepared according to the GATE exam syllabus. Information about Which of the following is correct output for the program code given below?main( ){void pr( );pr ( );pr ( );pr ( );void pr ( ){static int i = 1;printf (“%c”, (65+ i ++));}}a)BCDb)BBBc)ABCd)None of theseCorrect answer is option 'A'. Can you explain this answer? covers all topics & solutions for GATE 2024 Exam. Find important definitions, questions, meanings, examples, exercises and tests below for Which of the following is correct output for the program code given below?main( ){void pr( );pr ( );pr ( );pr ( );void pr ( ){static int i = 1;printf (“%c”, (65+ i ++));}}a)BCDb)BBBc)ABCd)None of theseCorrect answer is option 'A'. Can you explain this answer?.
Solutions for Which of the following is correct output for the program code given below?main( ){void pr( );pr ( );pr ( );pr ( );void pr ( ){static int i = 1;printf (“%c”, (65+ i ++));}}a)BCDb)BBBc)ABCd)None of theseCorrect answer is option 'A'. Can you explain this answer? in English & in Hindi are available as part of our courses for GATE. Download more important topics, notes, lectures and mock test series for GATE Exam by signing up for free.
Here you can find the meaning of Which of the following is correct output for the program code given below?main( ){void pr( );pr ( );pr ( );pr ( );void pr ( ){static int i = 1;printf (“%c”, (65+ i ++));}}a)BCDb)BBBc)ABCd)None of theseCorrect answer is option 'A'. Can you explain this answer? defined & explained in the simplest way possible. Besides giving the explanation of Which of the following is correct output for the program code given below?main( ){void pr( );pr ( );pr ( );pr ( );void pr ( ){static int i = 1;printf (“%c”, (65+ i ++));}}a)BCDb)BBBc)ABCd)None of theseCorrect answer is option 'A'. Can you explain this answer?, a detailed solution for Which of the following is correct output for the program code given below?main( ){void pr( );pr ( );pr ( );pr ( );void pr ( ){static int i = 1;printf (“%c”, (65+ i ++));}}a)BCDb)BBBc)ABCd)None of theseCorrect answer is option 'A'. Can you explain this answer? has been provided alongside types of Which of the following is correct output for the program code given below?main( ){void pr( );pr ( );pr ( );pr ( );void pr ( ){static int i = 1;printf (“%c”, (65+ i ++));}}a)BCDb)BBBc)ABCd)None of theseCorrect answer is option 'A'. Can you explain this answer? theory, EduRev gives you an ample number of questions to practice Which of the following is correct output for the program code given below?main( ){void pr( );pr ( );pr ( );pr ( );void pr ( ){static int i = 1;printf (“%c”, (65+ i ++));}}a)BCDb)BBBc)ABCd)None of theseCorrect answer is option 'A'. Can you explain this answer? tests, examples and also practice GATE tests.
Explore Courses for GATE exam
Signup for Free!
Signup to see your scores go up within 7 days! Learn & Practice with 1000+ FREE Notes, Videos & Tests.
10M+ students study on EduRev